<template>
</template>

<script>
	import base from '@/api/base'
	import store from '@/store/index'
	export default{
		data(){
			return {
				
			}
		},
		onLoad() {
			let that = this
			that.getOpenId()
		},
		methods:{
			getOpenId(){
				uni.login({
					success(res) {
						if(res.errMsg == 'login:ok'){
							console.log(res.code)
							store.dispatch('setLoginCode',res.code)
							uni.request({
								url:base.development_url + '/unionidLogin',
								data:{
									code:res.code
								},
								method:'POST',
								header:{
									'content-type':'application/json'
								},
								success(res) {
									let data = res.data
									if(data.code == 200){
										console.log("-------------")
										console.log(data.data)
										store.dispatch('setUserInfo',data.data)
										uni.navigateBack({
											delta:1
										})
									}else{
										uni.showToast({
											title:data.msg,
											duration:2000
										})
									}
								},
								fail(err) {
									uni.showToast({
										title:err,
										duration:2000
									})
								}
							})
						}
					},
					fail(err) {
						uni.showToast({
							title:err,
							duration:2000
						})
					}
				})
			}
		}
	}
</script>

<style>
</style>
